﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ObjectModel.PowerPoint.Events;
using System.Xml.Serialization;

namespace ObjectModel.PowerPoint
{
    [XmlInclude(typeof(ObservableShape))]
    public abstract class ObservableObject : ResolvableObject
    {
        public delegate void ObjectChangedEventHandler(object sender, ObjectChangedEventArgs e);
        
        public event ObjectChangedEventHandler Changed;
        public event EventHandler Deselected;
        public event EventHandler Selected;
        public event EventHandler SelectedExclusively;
        public event EventHandler TextSelectionChangedWithinShape;
        public event EventHandler Deleted;

        public abstract override object Resolve();

        public abstract void Restore();

        protected void OnChanged(ChangeType type)
        {
            if (Changed != null)
                Changed(this, new ObjectChangedEventArgs(type));
        }

        public virtual void OnDeselected()
        {
            if (Deselected != null)
                Deselected(this, new EventArgs());
        }

        public virtual void OnSelected()
        {
            if (Selected != null)
                Selected(this, new EventArgs());
        }

        public virtual void OnSelectedExclusively()
        {
            if (SelectedExclusively != null)
                SelectedExclusively(this, new EventArgs());
        }

        public virtual void OnDeleted()
        {
            if (Deleted != null)
                Deleted(this, new EventArgs());
        }

        public virtual void OnTextSelectionChangedWithinShape()
        {
            if (TextSelectionChangedWithinShape != null)
                TextSelectionChangedWithinShape(this, new EventArgs());
        }
    }
}
